
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_LocaleStringResourceDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            LocaleStringResource localeStringResource = LocaleStringResourceManager.GetByLocaleStringResourceID(this.LocaleStringResourceID);
            if (localeStringResource != null)
            {
                Language language = LanguageManager.GetByLanguageID(localeStringResource.LanguageID);
                if (language != null)
                    lblLanguage.Text = Server.HtmlEncode(language.Name);
                else
                    Response.Redirect("LocaleStringResources.aspx");

                hlBackToResources.NavigateUrl = "LocaleStringResources.aspx?LanguageID=" + localeStringResource.LanguageID.ToString();
                this.txtResourceName.Text = localeStringResource.ResourceName;
                this.txtResourceValue.Text = localeStringResource.ResourceValue;
            }
            else
                Response.Redirect("LocaleStringResources.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    LocaleStringResource localeStringResource = LocaleStringResourceManager.GetByLocaleStringResourceID(this.LocaleStringResourceID);

                    if (localeStringResource != null)
                    {
                        localeStringResource = LocaleStringResourceManager.UpdateLocaleStringResource(localeStringResource.LocaleStringResourceID,
                           localeStringResource.LanguageID, txtResourceName.Text, txtResourceValue.Text);

                        Response.Redirect("LocaleStringResources.aspx?LanguageID=" + localeStringResource.LanguageID.ToString());
                    }
                    else
                        Response.Redirect("LocaleStringResources.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                LocaleStringResourceManager.DeleteLocaleStringResource(this.LocaleStringResourceID);
                LocaleStringResource localeStringResource = LocaleStringResourceManager.GetByLocaleStringResourceID(this.LocaleStringResourceID);
                if (localeStringResource != null)
                    Response.Redirect("LocaleStringResources.aspx?LanguageID=" + localeStringResource.LanguageID.ToString());
                else
                    Response.Redirect("LocaleStringResources.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int LocaleStringResourceID
        {
            get
            {
                return CommonHelper.QueryStringInt("LocaleStringResourceID");
            }
        }
    }
}
